package com.xizi.factory.abstract1;

//电脑接口
interface Computer {
    public void printComputer();
}

class MacbookProComputer implements Computer {
    public void printComputer() {
        System.out.println("这是 a macbook pro");
    }
}

class SurfaceBookComputer implements Computer {
    public void printComputer() {
        System.out.println("这是 a surface book");
    }
}

//增加操作系统的接口
interface OperatingSystem {
    public void printSystem();
}

class MacOsSystem implements OperatingSystem {
    public void printSystem() {
        System.out.println("这是 mac os");
    }
}

class Windows8System implements OperatingSystem {
    public void printSystem() {
        System.out.println("这是 window 10");
    }
}

//产品的工厂
interface ProductionFactory {
    Computer createComputer();

    OperatingSystem createSystem();
}

class AppleFactory implements ProductionFactory {
    public Computer createComputer() {
        return new MacbookProComputer();
    }

    public OperatingSystem createSystem() {
        return new MacOsSystem();
    }
}

class MsFactory implements ProductionFactory {
    public Computer createComputer() {
        return new SurfaceBookComputer();
    }

    public OperatingSystem createSystem() {
        return new Windows8System();
    }
}

public class Client {

    public void buy(Computer c) {
        System.out.println("我想要买一台电脑");
        c.printComputer();
    }

    public void use(OperatingSystem s) {
        System.out.println("操作系统");
        s.printSystem();
    }

    public static void main(String[] args) {
        //创建一个apple的工厂
        ProductionFactory pf = new AppleFactory();
        Computer c = pf.createComputer(); //工厂创建一个电脑
        OperatingSystem s = pf.createSystem(); //工厂创建操作系统
        //客户进行购买
        Client client = new Client();
        client.buy(c);
        client.use(s);

    }
}
